﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace LearnDrive
{
    public partial class frmStudy : Form
    {
        public string code;
        public string shunxu;
        public DateTime mydt;
        public int tnum = 0;
        public int currentT = 0;
        public DataSet mydst;
        //public string id, TiXing, NeiRong, JiangJie, DaAn, ShengYin, TuPian, A, B, C, D;
        public string myDaAn;
        public Tbutton currentbutton;
        public List<Tbutton> mybtns = new List<Tbutton>();
        public bool isda = false;//本题是否答
        public int rightnum = 0;
        public int wrongnum = 0;
        public int weidanum = 0;
        public ShiTi[] DShiTi;
        public bool istime = false;
        string type = "";
        public Color bgcolor = Color.White;
        public int[] randarr;
        public int randrate = 5;
        public bool isshowcuoti = false;
        public bool isautocuoti = false;
        public frmStudy()
        {
            InitializeComponent();
        }
        public frmStudy(string mtype)
        {
            InitializeComponent();
            type = mtype;
        }
        public void onlyCuoTi()
        {
            for (int i = mybtns.Count - 1; i >= 0; i--)
            {
                Tbutton tb = mybtns[i];
                if (tb.Daancolor == Color.Black && tb.Daan != "")
                {
                    mybtns.Remove(tb);
                }
            }
            showbtn();
            isshowcuoti = true;
            button3.Visible = true;
            button4.Enabled = false;
        }
        public void showbtn()
        {

            panel12.Controls.Clear();
            int xp = 5, yp = 5;
            int width = panel12.Width;
            int anum = width / 20;
            int xnum = 20;
            int row = (int)Math.Ceiling((decimal)mybtns.Count / 20);
            if (row > panel12.Height / anum)
                anum = (width - 20) / 20;
            for (int i = 0; i < mybtns.Count; i++)
            {
                Tbutton tb = mybtns[i];
                tb.Location = new Point((i % xnum) * anum + xp, i / xnum * anum + yp);
                panel12.Controls.Add(tb);
                //tb.UserControlBtnClicked += new Tbutton.BtnClickHandle(tb_click);                
            }
        }
        public void showCuoTi()
        {
            DataSet myCuo = new DataSet();
            DataTable dt = mydst.Tables[0].Clone();
            foreach (Tbutton tb in mybtns)
            {
                int num = 0;
                int.TryParse(tb.Num, out num);
                if (num != 0)
                {
                    dt.Rows.Add(mydst.Tables[0].Rows[num - 1].ItemArray);
                }
            }
            myCuo.Tables.Add(dt);
            mydst = myCuo;
            tnum = mydst.Tables[0].Rows.Count;
            isshowcuoti = false;
            if (tnum > 0)
            {
                DShiTi = new ShiTi[tnum];
                getbutton(tnum);
                //mydt = DateTime.Now.AddMinutes(45);
                //timer1.Enabled = true;
                showT(0);
                rightnum = 0;
                wrongnum = 0;
                tongji();
            }
            button3.Visible = false;
            button4.Enabled = true;
        }
        private void frmStudy_Load(object sender, EventArgs e)
        {
            string cuoti;
            if (System.Configuration.ConfigurationManager.AppSettings["cuotimode"] != null)
            {
                cuoti = System.Configuration.ConfigurationManager.AppSettings["cuotimode"].ToString();
                if (cuoti == "auto")
                {
                    isautocuoti = true; 
                }
            }
            List<string> ls = AShelp.Load("rand");
            if (ls != null)
            {
                int.TryParse(ls[0], out randrate);
            }

            panel2.BackColor = bgcolor;
            gbShiTi.BackColor = bgcolor;
            groupBox10.BackColor = bgcolor;
            groupBox4.BackColor = bgcolor;
            lblT.BackColor = bgcolor;
            pbTP.BackColor = bgcolor;
            panel6.BackColor = bgcolor;
            panel10.BackColor = bgcolor;
            panel12.BackColor = bgcolor;
            panel11.BackColor = bgcolor;

            this.WindowState = FormWindowState.Maximized;
            this.TopMost = true;
            label1.Text = string.Format("第{0}考台", MySelect.changci);
            label2.Text = string.Format("考生姓名：{0}", Myinfo.usertruename);
            label4.Text = string.Format("报考车型：{0}", MySelect.typelx);
            label5.Text = string.Format("报考原因：{0}", MySelect.typekm);
            if (type == "cuoti")
            {
                checkBox5.Checked = true;
                checkBox6.Checked = true;
                button3.Visible = false;
                btnclearCT.Visible = true;
                mydst = AShelp.getCT();
            }
            else if (type == "fangzhen")
            {
                checkBox5.Checked = false;
                checkBox6.Checked = false;
                button3.Visible = false;
                btnclearCT.Visible = false;
                panel10.Visible = false;
                panel11.Visible = false;
                btnJT.Visible = false;
                pjiangjie.Visible = false;
                radioButton2.Checked = true;
                int KeMu1 = 0, KeMu4 = 0, HuiFu = 0;
                if (MySelect.typekm == "科目一")
                {
                    KeMu1 = 1;
                    mydt = DateTime.Now.AddMinutes(45);
                }
                else if (MySelect.typekm == "科目四")
                {
                    KeMu4 = 1;
                    mydt = DateTime.Now.AddMinutes(30);
                }
                else if (MySelect.typekm == "恢复驾照") HuiFu = 1;
                int cccc = 0, aab = 0, ab = 0, def = 0;
                if (MySelect.typelx == "C1C2C3C4") cccc = 1;
                else if (MySelect.typelx == "A1A3B1") aab = 1;
                else if (MySelect.typelx == "A2B2") ab = 1;
                else if (MySelect.typelx == "DEF") def = 1;
                mydst = AShelp.getTFZ(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def);

            }
            else if (type == "moni")
            {
                checkBox5.Checked = true;
                checkBox6.Checked = true;
                button3.Visible = false;
                mydst = getdsMN();
            }
            else if (MySelect.type == "1")
            {
                checkBox1.Checked = true;
                checkBox2.Checked = true;
                checkBox5.Checked = true;
                checkBox6.Checked = true;
                //checkBox3.Checked = true;
                checkBox4.Checked = true;
                button3.Visible = false;
                mydst = AShelp.getT(MySelect.codebm, MySelect.isrand);
            }
            //mydscount = mydst.Tables[0].Rows.Count;
            if (mydst != null)
            {
                tnum = mydst.Tables[0].Rows.Count;

                if (tnum > 0)
                {
                    DShiTi = new ShiTi[tnum];
                    int selectnum = tnum * randrate / 100;
                    randarr = AShelp.GetRandomNum(selectnum, tnum);
                    getbutton(tnum);

                    showT(0);
                    tongji();
                }
            }
            if (type == "fangzhen")
                timer1.Enabled = true;

        }
        private DataSet getdsMN()
        {
            int KeMu1 = 0, KeMu4 = 0, HuiFu = 0;
            if (MySelect.typekm == "科目一") KeMu1 = 1;
            else if (MySelect.typekm == "科目四") KeMu4 = 1;
            else if (MySelect.typekm == "恢复驾照") HuiFu = 1;
            int cccc = 0, aab = 0, ab = 0, def = 0;
            if (MySelect.typelx == "C1C2C3C4") cccc = 1;
            else if (MySelect.typelx == "A1A3B1") aab = 1;
            else if (MySelect.typelx == "A2B2") ab = 1;
            else if (MySelect.typelx == "DEF") def = 1;
            return AShelp.getT100(KeMu1, KeMu4, HuiFu, cccc, aab, ab, def, MySelect.Issucheng, MySelect.Isjichu, MySelect.Isqianghua, MySelect.Iszhuanxiang, MySelect.Iszhangjie, 0);
        }
        private void showT(int index)
        {

            if (index < tnum && index >= 0)
            {
                AShelp.Stop();
                //pduoxuan.Visible = false;
                //pnoduanxuan.Visible = true;
                lbldaan.Text = "";
                if (DShiTi[index] == null)
                {
                    ShiTi s = new ShiTi();
                    s.id = mydst.Tables[0].Rows[index]["id"].ToString();
                    s.TiXing = mydst.Tables[0].Rows[index]["TiXing"].ToString();
                    s.NeiRong = mydst.Tables[0].Rows[index]["NeiRong"].ToString();
                    s.JiangJie = mydst.Tables[0].Rows[index]["JiangJie"].ToString();
                    s.DaAn = mydst.Tables[0].Rows[index]["DaAn"].ToString().Trim();
                    s.ShengYin = mydst.Tables[0].Rows[index]["ShengYin"].ToString();
                    s.TuPian = mydst.Tables[0].Rows[index]["TuPian"].ToString();
                    s.showtxt = (index + 1).ToString() + "." + s.NeiRong + "\r\n\r\n";
                    //lblT.Text = (index + 1).ToString() + "、" + NeiRong + "\r\n";
                    if (s.TiXing != "1")
                    {

                        s.DaAn = s.DaAn.Replace('1', 'A').Replace('2', 'B').Replace('3', 'C').Replace('4', 'D');
                        //随机比例
                        if (AShelp.IsInRand(randarr, index))
                        {
                            string t = mydst.Tables[0].Rows[index]["D"].ToString();
                            if (t != "")
                            {
                                string[] arr = new string[] { "A", "B", "C", "D" };
                                string[] r = AShelp.GetRandomArray(arr);
                                s.A = mydst.Tables[0].Rows[index][r[0]].ToString().Replace("\n", "").Trim();
                                s.B = mydst.Tables[0].Rows[index][r[1]].ToString().Replace("\n", "").Trim();
                                s.C = mydst.Tables[0].Rows[index][r[2]].ToString().Replace("\n", "").Trim();
                                s.D = mydst.Tables[0].Rows[index][r[3]].ToString().Replace("\n", "").Trim();
                                s.DaAn = s.DaAn.Replace(r[0], "1").Replace(r[1], "2").Replace(r[2], "3").Replace(r[3], "4");
                                s.DaAn = s.DaAn.Replace('1', 'A').Replace('2', 'B').Replace('3', 'C').Replace('4', 'D');
                                s.showtxt += "A:" + s.A + "\r\n\r\n";
                                s.showtxt += "B:" + s.B + "\r\n\r\n";
                                s.showtxt += "C:" + s.C + "\r\n\r\n";
                                s.showtxt += "D:" + s.D + "\r\n";
                            }
                            else
                            {
                                string[] arr = new string[] { "A", "B", "C" };
                                string[] r = AShelp.GetRandomArray(arr);
                                s.A = mydst.Tables[0].Rows[index][r[0]].ToString().Replace("\n", "").Trim();
                                s.B = mydst.Tables[0].Rows[index][r[1]].ToString().Replace("\n", "").Trim();
                                s.C = mydst.Tables[0].Rows[index][r[2]].ToString().Replace("\n", "").Trim();
                                s.DaAn = s.DaAn.Replace(r[0], "1").Replace(r[1], "2").Replace(r[2], "3");
                                s.DaAn = s.DaAn.Replace('1', 'A').Replace('2', 'B').Replace('3', 'C');
                                s.showtxt += "A:" + s.A + "\r\n";
                                s.showtxt += "B:" + s.B + "\r\n";
                                s.showtxt += "C:" + s.C + "\r\n";
                            }
                        }
                        else
                        {
                            string t = mydst.Tables[0].Rows[index]["D"].ToString();
                            if (t != "")
                            {
                                s.A = mydst.Tables[0].Rows[index]["A"].ToString().Replace("\n", "").Trim();
                                s.B = mydst.Tables[0].Rows[index]["B"].ToString().Replace("\n", "").Trim();
                                s.C = mydst.Tables[0].Rows[index]["C"].ToString().Replace("\n", "").Trim();
                                s.D = mydst.Tables[0].Rows[index]["D"].ToString().Replace("\n", "").Trim();
                                s.showtxt += "A:" + s.A + "\r\n\r\n";
                                s.showtxt += "B:" + s.B + "\r\n\r\n";
                                s.showtxt += "C:" + s.C + "\r\n\r\n";
                                s.showtxt += "D:" + s.D + "\r\n";
                            }
                            else
                            {
                                s.A = mydst.Tables[0].Rows[index]["A"].ToString().Replace("\n", "").Trim();
                                s.B = mydst.Tables[0].Rows[index]["B"].ToString().Replace("\n", "").Trim();
                                s.C = mydst.Tables[0].Rows[index]["C"].ToString().Replace("\n", "").Trim();
                                s.showtxt += "A:" + s.A + "\r\n";
                                s.showtxt += "B:" + s.B + "\r\n";
                                s.showtxt += "C:" + s.C + "\r\n";
                            }

                        }
                        if (s.TiXing == "3")
                        {
                            string t1 = "";
                            if (s.DaAn.Contains("A"))
                            {
                                t1 += "A";
                            }
                            if (s.DaAn.Contains("B"))
                            {
                                t1 += "B";
                            }
                            if (s.DaAn.Contains("C"))
                            {
                                t1 += "C";
                            }
                            if (s.DaAn.Contains("D"))
                            {
                                t1 += "D";
                            }
                            s.DaAn = t1;

                        }
                    }
                    else
                    {
                        s.DaAn = s.DaAn.Replace('1', '√').Replace('2', '×');
                    }
                    DShiTi[index] = s;
                }
                if (type != "cuoti")
                {
                    if (type == "fangzhen")
                        gbShiTi.Text = "考试题目－仿真考试-" + "ID=" + DShiTi[index].id;
                    else if (type == "moni")
                        gbShiTi.Text = "考试题目－模拟-" + "ID=" + DShiTi[index].id;
                    else
                        gbShiTi.Text = "考试题目－" + MySelect.zhangjie + "-" + MySelect.zhangjie_s + "-" + "ID=" + DShiTi[index].id;
                    lblT.Text = AShelp.FilterHTML(DShiTi[index].showtxt);
                }
                else
                {
                    gbShiTi.Text = "考试题目－错题-ID=" + DShiTi[index].id;
                    lblT.Text = AShelp.FilterHTML(DShiTi[index].showtxt);
                }

                if (DShiTi[index].TiXing != "1")
                {

                    //random
                    pnoduanxuan.Visible = true;
                    pdanxuan.Visible = false;
                    string t = DShiTi[index].D;
                    if (t != "")
                    {
                        btnC.Visible = true;
                        btnD.Visible = true;
                    }
                    else
                    {
                        btnC.Visible = true;
                        btnD.Visible = false;
                    }
                    if (DShiTi[index].TiXing == "2")
                    {
                        lblmsg.Text = "单项选择题：请选择您认为正确的一个";
                        button1.Visible = false;
                    }
                    else if (DShiTi[index].TiXing == "3")
                    {
                        button1.Visible = true;
                        lblmsg.Text = "多项选择题：请选择您认为正确的一项或多项，然后点确定";
                    }
                    else
                    {
                        button1.Visible = false;
                    }

                }
                else
                {
                    lblmsg.Text = "判断题：选择正确或错误";
                    //btnA.Text = "√";
                    //btnB.Text = "×";
                    //btnC.Visible = false;
                    //btnD.Visible = false;
                    pdanxuan.Visible = true;
                    pnoduanxuan.Visible = false;
                    button1.Visible = false;
                }
                if (DShiTi[index].TuPian != "")
                {
                    string path = AShelp.getPic(DShiTi[index].TuPian);
                    if (path != "")
                    {
                        pbTP.Image = Image.FromFile(path);
                        pbTP.Visible = true;
                    }
                    else
                    {
                        pbTP.Visible = false;
                    }
                }
                else
                {
                    pbTP.Image = null;
                    pbTP.Visible = false;
                }

                if (checkBox3.Checked)//显示题解
                {
                    pjiangjie.Visible = checkBox3.Checked;

                }
                else
                {
                    pjiangjie.Visible = false;
                }
                lbljiangjie.Text = DShiTi[index].JiangJie;
                if (checkBox4.Checked)
                {
                    string path = AShelp.getPic(DShiTi[index].ShengYin);
                    if (path != "")
                    {

                        btnJT.Visible = true;
                        //AShelp.Play("temp\\" + DShiTi[index].ShengYin);
                    }
                    else
                    {
                        btnJT.Visible = false;
                    }
                }
                else
                {
                    btnJT.Visible = false;
                }
                foreach (Tbutton mt in mybtns)
                {
                    mt.Bgcolor = bgcolor;
                    if (mt.Num == (index + 1).ToString())
                        currentbutton = mt;
                }
                currentbutton.Bgcolor = Color.Gold;
                if (currentbutton.Daan == "")
                {
                    isda = false;
                    lblselect.Text = "您的选择：";
                    if (checkBox2.Checked)
                    {
                        pictureBox2.Visible = false;
                    }
                }
                else
                {
                    lblselect.Text = "您的选择：" + currentbutton.Daan;
                    isda = true;
                    if (checkBox2.Checked)
                    {
                        if (currentbutton.Daan == DShiTi[index].DaAn)
                            pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\sysvoice\\right.bmp");
                        else
                            pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\sysvoice\\wrong.bmp");
                    }
                    else
                    {
                        pictureBox2.Visible = false;
                    }
                }
                currentT = index;
            }
        }
        private void getbutton(int num)
        {
            mybtns.Clear();
            panel12.Controls.Clear();
            int xp = 5, yp = 5;
            int width = panel12.Width;

            int anum = width / 20;
            int xnum = 20;
            int row = (int)Math.Ceiling((decimal)num / 20);
            if (row > panel12.Height / anum)
                anum = (width - 20) / 20;
            for (int i = 0; i < num; i++)
            {
                Tbutton tb = new Tbutton();
                tb.BackColor = bgcolor;
                tb.Bgcolor = bgcolor;
                tb.Num = (i + 1).ToString();
                tb.Whsize = anum - 4;
                tb.Location = new Point((i % xnum) * anum + xp, i / xnum * anum + yp);
                panel12.Controls.Add(tb);
                tb.UserControlBtnClicked += new Tbutton.BtnClickHandle(tb_click);
                mybtns.Add(tb);
            }
        }
        private void tb_click(object sender, EventArgs e)
        {
            Tbutton t = sender as Tbutton;
            if (t != null)
            {
                int num = 0;
                int.TryParse(t.Num, out num);
                if (num != 0)
                {
                    showT(num - 1);
                }
            }
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (DateTime.Now < mydt)
                lbltime.Text = AShelp.DateDiffshort(DateTime.Now, mydt);
            else
            {
                //交
                if (!istime)
                {
                    istime = true;
                    frmSum f = new frmSum((float)rightnum / tnum * 100, this);
                    f.ShowDialog();
                }
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (isshowcuoti)
            {
                for (int i = 0; i < mybtns.Count; i++)
                {
                    if (mybtns[i].Num == (currentT+1).ToString())
                    {
                        if (i -1>= 0)
                        {
                            int.TryParse(mybtns[i - 1].Num, out currentT);
                            //currentT = currentT+ 1;
                        }
                        else
                        {
                            currentT =0;
                        }
                        break;
                    }
                }
            }
            if (currentT > 0)
            {
                showT(currentT - 1);
            }
            else
            {
                MessageBox.Show("已经是第一题了！");
            }
        }

        private void btnnext_Click(object sender, EventArgs e)
        {
            if (isshowcuoti)
            {
                for (int i = 0; i < mybtns.Count; i++)
                {
                    if (mybtns[i].Num == (currentT+1).ToString())
                    {
                        if (i + 1 < mybtns.Count)
                        {
                            int.TryParse(mybtns[i + 1].Num, out currentT);
                            currentT = currentT - 2;
                        }
                        else
                        {
                            currentT = tnum - 1;
                        }
                        break;
                    }
                }
            }
            if (currentT < tnum - 1)
            {
                showT(currentT + 1);
            }
            else
            {
                MessageBox.Show("已经是最后一题了！");
            }
        }

        private void btnA_Click(object sender, EventArgs e)
        {
            Button b = sender as Button;
            if (b != null)
            {
                if (DShiTi[currentT].TiXing != "3")
                {
                    if (!isda)
                    {
                        myDaAn = b.Text;
                        lblselect.Text = "您的选择：" + myDaAn;
                        currentbutton.Daan = myDaAn;
                        isda = true;
                        if (myDaAn == DShiTi[currentT].DaAn)
                        {
                            currentbutton.Daancolor = Color.Black;
                            rightnum++;
                            if (checkBox5.Checked)
                            {
                                AShelp.Play("sysvoice\\对.wav");
                            }
                            if (checkBox2.Checked)
                            {
                                pictureBox2.Visible = true;
                                pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\sysvoice\\right.bmp");
                            }
                            else
                            {
                                pictureBox2.Visible = false;
                            }
                            if (radioButton3.Checked)
                            {
                                showT(currentT + 1);
                            }
                            else
                            {
                                if (checkBox1.Checked)//显示答案
                                {
                                    lbldaan.Visible = true;
                                    lbldaan.Text = "答案：" + DShiTi[currentT].DaAn;
                                }
                            }
                            //删除错题
                            if (type == "cuoti" && isautocuoti)
                            {
                                int id = 0;
                                int.TryParse(DShiTi[currentT].id, out id);
                                if (id > 0)
                                    AShelp.delCT(id);
                            }
                        }
                        else
                        {
                            currentbutton.Daancolor = Color.Red;
                            wrongnum++;
                            if (type == "fangzhen")
                            {
                                if (MySelect.typekm == "科目一")
                                {
                                    if (wrongnum > 10)
                                    {
                                        frmSum f = new frmSum((float)rightnum / tnum * 100, this);
                                        f.ShowDialog();

                                    }
                                }
                                else if (MySelect.typekm == "科目四")
                                {
                                    if (wrongnum > 5)
                                    {
                                        frmSum f = new frmSum((float)rightnum / tnum * 100, this);
                                        f.ShowDialog();

                                    }
                                }
                            }
                            if (checkBox5.Checked)
                            {
                                if (DShiTi[currentT].DaAn == "√")
                                {
                                    AShelp.Play("sysvoice\\正确.wav");
                                }
                                else if (DShiTi[currentT].DaAn == "×")
                                {
                                    AShelp.Play("sysvoice\\错误.wav");
                                }
                                if (DShiTi[currentT].DaAn.Contains("A"))
                                {
                                    AShelp.Play("sysvoice\\A.wav");
                                }
                                if (DShiTi[currentT].DaAn.Contains("B"))
                                {
                                    AShelp.Play("sysvoice\\B.wav");
                                }
                                if (DShiTi[currentT].DaAn.Contains("C"))
                                {
                                    AShelp.Play("sysvoice\\C.wav");
                                }
                                if (DShiTi[currentT].DaAn.Contains("D"))
                                {
                                    AShelp.Play("sysvoice\\D.wav");
                                }
                            }
                            if (checkBox6.Checked)
                            {
                                if (DShiTi[currentT] != null)
                                {
                                    string path = AShelp.getPic(DShiTi[currentT].ShengYin);
                                    if (path != "")
                                    {
                                        AShelp.Play("temp\\" + DShiTi[currentT].ShengYin);
                                    }
                                }
                            }
                            if (checkBox1.Checked)//显示答案
                            {
                                lbldaan.Visible = true;
                                lbldaan.Text = "答案：" + DShiTi[currentT].DaAn;
                            }
                            if (checkBox2.Checked)
                            {
                                pictureBox2.Visible = true;
                                pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\sysvoice\\wrong.bmp");
                            }
                            else
                            {
                                pictureBox2.Visible = false;
                            }
                            //插入错题库
                            int id = 0;
                            int.TryParse(DShiTi[currentT].id, out id);
                            if (id > 0)
                                AShelp.insertCT(id);
                        }
                        tongji();
                        if (radioButton2.Checked)
                        {
                            showT(currentT + 1);
                        }

                    }
                }
                else
                {
                    //多选 
                    if (!isda)
                    {
                        myDaAn = b.Text;
                        string an = lblselect.Text;
                        string daan = an.Substring(5);
                        if (!daan.Contains(myDaAn))
                        {
                            daan = daan + myDaAn;

                        }
                        else
                        {
                            daan = daan.Replace(myDaAn, "");

                        }
                        string t = "";
                        if (daan.Contains("A"))
                        {
                            t += "A";
                        }
                        if (daan.Contains("B"))
                        {
                            t += "B";
                        }
                        if (daan.Contains("C"))
                        {
                            t += "C";
                        }
                        if (daan.Contains("D"))
                        {
                            t += "D";
                        }
                        daan = t;
                        lblselect.Text = "您的选择：" + daan;
                    }

                }
            }
        }
        private void tongji()
        {
            label7.Text = string.Format("抽题数量{0}道", tnum);
            lblduinum.Text = string.Format("{0}道", rightnum);
            lblcuonum.Text = string.Format("{0}道", wrongnum);
            lblweidanum.Text = string.Format("{0}道", tnum - rightnum - wrongnum);
            if (rightnum + wrongnum > 0)
            {
                string fen = ((float)rightnum / (rightnum + wrongnum) * 100).ToString("F2");
                lblzhenglvnum.Text = string.Format("{0}%", fen);
                lbldabi.Text = string.Format("{0}分", fen);
            }
            else
            {
                lblzhenglvnum.Text = string.Format("{0}%", 0);
                lbldabi.Text = string.Format("{0}分", 0);
            }
            lblchoubi.Text = string.Format("{0}分", ((float)rightnum / tnum * 100).ToString("F2"));
        }

        private void btnJT_Click(object sender, EventArgs e)
        {
            if (DShiTi[currentT] != null)
            {
                string path = AShelp.getPic(DShiTi[currentT].ShengYin);
                if (path != "")
                {
                    AShelp.Play("temp\\" + DShiTi[currentT].ShengYin);
                }
            }
        }

        private void pbTP_DoubleClick(object sender, EventArgs e)
        {
            if (pbTP.Image != null)
            {
                frmPic f = new frmPic(pbTP.Image);
                f.ShowDialog();
            }
        }

        private void frmStudy_FormClosing(object sender, FormClosingEventArgs e)
        {
            AShelp.Stop();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            AShelp.Stop();
            int num = tnum - wrongnum - rightnum;
            if (num > 0)
            {
                if (MessageBox.Show("还有" + num + "道题没有做，您确定要交卷吗？", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    frmSum f = new frmSum((float)rightnum / tnum * 100, this);
                    f.ShowDialog();
                }
            }
            else
            {
                frmSum f = new frmSum((float)rightnum / tnum * 100, this);
                f.ShowDialog();
            }

        }

        private void button3_Click(object sender, EventArgs e)
        {
            showCuoTi();
        }

        private void btnclearCT_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您确定要清空错题吗？", "提示", MessageBoxButtons.YesNo) == DialogResult.Yes)
            {
                AShelp.clearCT();
                MessageBox.Show("清空错成功！");
                this.Close();
            }
        }

        private void checkBox4_CheckedChanged(object sender, EventArgs e)
        {

            btnJT.Visible = checkBox4.Checked;
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            string an = lblselect.Text;
            string daan = an.Substring(5);
            currentbutton.Daan = daan;
            isda = true;
            if (daan == DShiTi[currentT].DaAn)
            {
                currentbutton.Daancolor = Color.Black;
                rightnum++;
                if (checkBox5.Checked)
                {
                    AShelp.Play("sysvoice\\对.wav");
                }
                if (checkBox2.Checked)
                {
                    pictureBox2.Visible = true;
                    pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\sysvoice\\right.bmp");
                }
                else
                {
                    pictureBox2.Visible = false;
                }
                if (radioButton3.Checked)
                {
                    showT(currentT + 1);
                }
                else
                {
                    if (checkBox1.Checked)//显示答案
                    {
                        lbldaan.Visible = true;
                        lbldaan.Text = "答案：" + DShiTi[currentT].DaAn;
                    }
                }
                //删除错题
                if (type == "cuoti" && isautocuoti)
                {
                    int id = 0;
                    int.TryParse(DShiTi[currentT].id, out id);
                    if (id > 0)
                        AShelp.delCT(id);
                }
            }
            else
            {
                currentbutton.Daancolor = Color.Red;
                wrongnum++;
                if (type == "fangzhen")
                {
                    if (MySelect.typekm == "科目一")
                    {
                        if (wrongnum > 10)
                        {
                            frmSum f = new frmSum((float)rightnum / tnum * 100, this);
                            f.ShowDialog();

                        }
                    }
                    else if (MySelect.typekm == "科目四")
                    {
                        if (wrongnum > 5)
                        {
                            frmSum f = new frmSum((float)rightnum / tnum * 100, this);
                            f.ShowDialog();

                        }
                    }
                }
                if (checkBox5.Checked)
                {
                    if (DShiTi[currentT].DaAn == "√")
                    {
                        AShelp.Play("sysvoice\\正确.wav");
                    }
                    else if (DShiTi[currentT].DaAn == "×")
                    {
                        AShelp.Play("sysvoice\\错误.wav");
                    }
                    if (DShiTi[currentT].DaAn.Contains("A"))
                    {
                        AShelp.Play("sysvoice\\A.wav");
                    }
                    if (DShiTi[currentT].DaAn.Contains("B"))
                    {
                        AShelp.Play("sysvoice\\B.wav");
                    }
                    if (DShiTi[currentT].DaAn.Contains("C"))
                    {
                        AShelp.Play("sysvoice\\C.wav");
                    }
                    if (DShiTi[currentT].DaAn.Contains("D"))
                    {
                        AShelp.Play("sysvoice\\D.wav");
                    }
                }
                if (checkBox6.Checked)
                {
                    if (DShiTi[currentT] != null)
                    {
                        string path = AShelp.getPic(DShiTi[currentT].ShengYin);
                        if (path != "")
                        {
                            AShelp.Play("temp\\" + DShiTi[currentT].ShengYin);
                        }
                    }
                }
                if (checkBox1.Checked)//显示答案
                {
                    lbldaan.Visible = true;
                    lbldaan.Text = "答案：" + DShiTi[currentT].DaAn;
                }
                if (checkBox2.Checked)
                {
                    pictureBox2.Visible = true;
                    pictureBox2.Image = Image.FromFile(Application.StartupPath + "\\sysvoice\\wrong.bmp");
                }
                else
                {
                    pictureBox2.Visible = false;
                }
                //插入错题库
                int id = 0;
                int.TryParse(DShiTi[currentT].id, out id);
                if (id > 0)
                    AShelp.insertCT(id);
            }
            tongji();
            if (radioButton2.Checked)
            {
                showT(currentT + 1);
            }
        }

        private void checkBox3_CheckedChanged(object sender, EventArgs e)
        {
            pjiangjie.Visible = checkBox3.Checked;
        }
    }
}
